Last chance! 50% off unlimited learning
Sale ends in
These functions are global which, which.max and which.min applying on distributed data for all ranks.
comm.which(x, arr.ind = FALSE, useNames = TRUE,
comm = .pbd_env$SPMD.CT$comm)
comm.which.max(x, comm = .pbd_env$SPMD.CT$comm)
comm.which.min(x, comm = .pbd_env$SPMD.CT$comm)
The global values (which()
, which.max()
, or which.min()
)
are returned to all ranks.
comm.which()
returns with two columns, 'rank id' and 'index of
TRUE
'.
comm.which.max()
and comm.which.min()
return with three
values, 'the _smallest_ rank id', 'index of the _first_ maximum or minimum',
and 'max/min value of x
'.
a 'logical' vector or array as in which()
,
or an 'numeric' objects in which.max()
and
which.min()
.
logical, as in which()
.
logical, as in which()
.
a communicator number.
Wei-Chen Chen wccsnow@gmail.com, George Ostrouchov, Drew Schmidt, Pragneshkumar Patel, and Hao Yu.
These functions will apply which()
, which.max()
and
which.min()
locally, and apply allgather()
to get all local
results from other ranks.
Programming with Big Data in R Website: https://pbdr.org/
comm.read.table()
if (FALSE) {
### Save code in a file "demo.r" and run with 2 processors by
### SHELL> mpiexec -np 2 Rscript demo.r
spmd.code <- "
### Initialize
suppressMessages(library(pbdMPI, quietly = TRUE))
if(comm.size() != 2){
comm.cat(\"2 processors are requried.\n\", quiet = TRUE)
finalize()
}
### Examples.
a <- 1:(comm.rank() + 1)
b <- comm.which(a == 2)
comm.print(b)
b <- comm.which.max(a)
comm.print(b)
b <- comm.which.min(a)
comm.print(b)
### Finish.
finalize()
"
# execmpi(spmd.code, nranks = 2L)
}
Run the code above in your browser using DataLab